package com.zhangc.blog.base.validator;

/**
 * 功能描述:<br>
 *
 * @author wx:fdzhangc
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
public abstract class Validators {
    private static ServiceExceptionFactory serviceExceptionFactory;

    public static void setServiceExceptionFactory(ServiceExceptionFactory factory) {
        if (serviceExceptionFactory == null) {
            serviceExceptionFactory = factory;
        }

    }

    public static void throwAnyway(ServiceExceptionNameProvider provider, Object... args) {
        throw createException(provider, args);
    }

    public static ServiceException createException(ServiceExceptionNameProvider provider, Object... args) {
        return serviceExceptionFactory != null ?
                serviceExceptionFactory.create(provider, args) :
                new ServiceException(provider.getName(), args);
    }
}
